package com.yupi.yuoj.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum JudgeInfoMessageEnum {

    NO_SUBMIT("未提交", "No Submit", 0),
    ACCEPTED("成功", "Accepted", 1),
    WRONG_ANSWER("答案错误", "Wrong Answer", 2),
    COMPILE_ERROR( "编译错误", "Compile Error", 3),
    MEMORY_LIMIT_EXCEEDED( "内存溢出", "Out Of Memory", 4),
    TIME_LIMIT_EXCEEDED( "超时", "Time Limit Exceeded", 5),
    PRESENTATION_ERROR( "展示错误", "Presentation Error", 6),
    WAITING( "等待中", "Waiting", 7),
    OUTPUT_LIMIT_EXCEEDED( "输出溢出", "Output Limit Exceeded", 8),
    DANGEROUS_OPERATION( "危险操作", "Dangerous Operation", 9),
    RUNTIME_ERROR( "运行错误", "Runtime Error", 10),
    SYSTEM_ERROR( "系统错误", "System Error", 11);

    private final String text;

    private final String value;

    private final int sign;

    JudgeInfoMessageEnum(String text, String value, int sign) {
        this.text = text;
        this.value = value;
        this.sign = sign;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static JudgeInfoMessageEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (JudgeInfoMessageEnum anEnum : JudgeInfoMessageEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }

    public int getSign() {
        return sign;
    }
}
